package com.jic.manager.impl;

import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.CustomerServiceManagementMapper;
import com.jic.manager.entity.CustomerServiceManagement;
import com.jic.conf.request.CustomerServiceManagementRequest;
import com.jic.manager.service.CustomerServiceManagementService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * @author : 
 * @email : 
 * @since : 2020-02-25 04:17:44
 * @version : v1.0.0
 */
@Service
public class CustomerServiceManagementServiceImpl implements CustomerServiceManagementService{

    @Autowired
    private CustomerServiceManagementMapper customerServiceManagementMapper;

    @Override
    public long insert(CustomerServiceManagementRequest param) {
        CustomerServiceManagement customerServiceManagement = new CustomerServiceManagement();
        BeanUtils.copyProperties(param,customerServiceManagement);
        customerServiceManagement.setCreator(null!=param.getAccount()?param.getAdminOperate().getOperator():0);
        customerServiceManagement.setCreatorName(null!=param.getAccount()?param.getAdminOperate().getOperateName():"");
        customerServiceManagement.setDeptId(param.getAdminOperate().getDeptId());
        return customerServiceManagementMapper.insert(customerServiceManagement);
    }

    @Override
    public long delete(CustomerServiceManagementRequest param) {
        CustomerServiceManagement customerServiceManagement = new CustomerServiceManagement();
        BeanUtils.copyProperties(param,customerServiceManagement);
        return customerServiceManagementMapper.delete(customerServiceManagement);
    }

    @Override
    public long update(CustomerServiceManagementRequest param) {
        CustomerServiceManagement customerServiceManagement = new CustomerServiceManagement();
        BeanUtils.copyProperties(param,customerServiceManagement);
        customerServiceManagement.setUpdater(null!=param.getAccount()?param.getAdminOperate().getOperator():0);
        customerServiceManagement.setUpdaterName(null!=param.getAccount()?param.getAdminOperate().getOperateName():"");
        return customerServiceManagementMapper.update(customerServiceManagement);
    }

    @Override
    public CustomerServiceManagement queryByPrimaryKey(Long id){
        return customerServiceManagementMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CustomerServiceManagement> query(CustomerServiceManagement customerServiceManagement){
        return customerServiceManagementMapper.query(customerServiceManagement);
    }

    @Override
    public PageResult<CustomerServiceManagement> queryPage(CustomerServiceManagementRequest param) {
        //计算下标
        int startIndex = (param.getStart() - 1) * param.getLimit();
        List<CustomerServiceManagement> list = customerServiceManagementMapper.queryPage(startIndex, param.getLimit(), param);
        long count = customerServiceManagementMapper.queryPageCount(param);

        PageResult<CustomerServiceManagement> pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}